import { _decorator, Component, Node, System } from 'cc';
const { ccclass, property } = _decorator;


@ccclass('OnClickDownloadBtn')
export class OnClickDownloadBtn extends Component {

    @property(Boolean)
    IsCTA: Boolean = false;

    start() {
        const google_play = "https://play.google.com/store/apps/details?id=com.unity3d.auicreativetestapp";
        const appstore = "https://apps.apple.com/us/app/ad-testing/id1463016906";

        this.set_google_play_url(google_play);
        this.set_app_store_url(appstore);
    }

    update(deltaTime: number) {
        
    }

    onClick(){
        if(this.IsCTA){
            this.game_end();
        }
        else{
            this.download();
        }
    }

      download() {
        console.log("download");
        //@ts-ignore
        window.super_html && super_html.download();
    }

    game_end() {
        console.log("game end");
        //@ts-ignore
        window.super_html && super_html.game_end();
    }

    /**
     * 是否隐藏下载按钮，意味着使用平台注入的下载按钮
     * channel : google
     */
    is_hide_download() {
        //@ts-ignore
        if (window.super_html && super_html.is_hide_download) {
            //@ts-ignore
            return super_html.is_hide_download();
        }
        return false
    }

    /**
     * 设置商店地址
     * channel : unity
     * @param url https://play.google.com/store/apps/details?id=com.unity3d.auicreativetestapp
     */
    set_google_play_url(url: string) {
        //@ts-ignore
        window.super_html && (super_html.google_play_url = url);
    }

    /**
    * 设置商店地址
    * channel : unity
    * @param url https://apps.apple.com/us/app/ad-testing/id1463016906
    */
    set_app_store_url(url: string) {
        //@ts-ignore
        window.super_html && (super_html.appstore_url = url);
    }

    /**
    * 是否开启声音
    * channel : ironsource
    */
    is_audio() {
        //@ts-ignore
        return (window.super_html && super_html.is_audio()) || true;
    }

}


